﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ServiceModel.DomainServices.Client;

namespace Candy.Model
{
    public abstract class CandyOperationBase
    {

        protected OperationBase _operation;
        private Exception exception;

        public Exception Error { get; private set; }


        public bool HasError
        {
            get
            {
                return Error != null;
            }
        }

        private bool _isErrorHandled;

        public bool IsErrorHandled
        {
            get
            {
                if (_operation != null)
                    return _operation.IsErrorHandled;
                else
                    return _isErrorHandled;

            }
        }


        private bool _isCanceled;
        public bool IsCanceled
        {
            get
            {
                if (_operation != null)
                    return _operation.IsCanceled;
                else
                    return _isCanceled;
            }

        }

        public void Cancel()
        {
            if (_operation != null)
                _operation.Cancel();
            _isCanceled = true;
        }


        public CandyOperationBase(OperationBase operation)
            : this(operation.Error)
        {

            _operation = operation;
            Error = operation.Error;

        }

        public CandyOperationBase(Exception exception)
        {
            this.exception = exception;
        }



        public void MarkErrorAsHandled()
        {
            if (_operation != null)
                _operation.MarkErrorAsHandled();
            else
                _isErrorHandled = true;

        }
    }
}
